package com.service.sys;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.common.base.BaseService;
import com.entity.sys.SysLog;
import com.entity.sys.query.SysQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.sys.SysLogMapper;
import org.springframework.stereotype.Service;


/**
 * 系统日志 服务实现类
 */
@Service
public class SysLogService extends BaseService<SysLogMapper, SysLog>{

    /**
     * 日志列表
     */
    public PageInfo<SysLog> page(SysQuery query){
        QueryWrapper<SysLog> queryWrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(query.getName())){
            queryWrapper.like("create_by",query.getName());
        }
        if (StrUtil.isNotBlank(query.getCode())){
            queryWrapper.like("ip",query.getCode());
        }
        if (StrUtil.isNotBlank(query.getStartDate())){
            queryWrapper.eq("DATE_FORMAT(create_time,'%Y-%m-%d')",query.getStartDate());
        }
        queryWrapper.orderByDesc("create_time");
        PageHelper.startPage(query.getPageNum(),query.getPageSize());
        return new PageInfo<>(baseMapper.selectList(queryWrapper));
    }
}
